# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This will parse a textual representation of a duration. The formats
# accepted are based on the ISO-8601 duration format {@code PnDTnHnMn.nS}
# with days considered to be exactly 24 hours.
# <p>
# Examples:
# <pre>
#    "PT20.345S" -- parses as "20.345 seconds"
#    "PT15M"     -- parses as "15 minutes" (where a minute is 60 seconds)
#    "PT10H"     -- parses as "10 hours" (where an hour is 3600 seconds)
#    "P2D"       -- parses as "2 days" (where a day is 24 hours or 86400 seconds)
#    "P2DT3H4M"  -- parses as "2 days, 3 hours and 4 minutes"
#    "P-6H3M"    -- parses as "-6 hours and +3 minutes"
#    "-P6H3M"    -- parses as "-6 hours and -3 minutes"
#    "-P-6H+3M"  -- parses as "+6 hours and -3 minutes"
# </pre>
filter: "{ tags -> tags.job_name == 'rabbitmq-monitoring' }" # The OpenTelemetry job name
expSuffix: tag({tags -> tags.cluster = 'rabbitmq::' + tags.cluster}).instance(['cluster'], ['node'], Layer.RABBITMQ)
metricPrefix: meter_rabbitmq_node
metricsRules:
  - name: queue_messages_ready
    exp: rabbitmq_queue_messages_ready.sum(['cluster', 'node'])
  - name: incoming_messages
    exp: rabbitmq_global_messages_received_total.sum(['cluster', 'node']).rate('PT1M')
  - name: publisher_total
    exp: rabbitmq_channels.sum(['cluster', 'node']) - rabbitmq_channel_consumers.sum(['cluster', 'node'])
  - name: connections_total
    exp: rabbitmq_connections.sum(['cluster', 'node'])
  - name: queue_total
    exp: rabbitmq_queues.sum(['cluster', 'node'])
  - name: unacknowledged_messages
    exp: rabbitmq_queue_messages_unacked.sum(['cluster', 'node'])
  - name: outgoing_messages_total
    exp: rabbitmq_global_messages_redelivered_total.sum(['cluster', 'node']).rate('PT1M') + rabbitmq_global_messages_delivered_consume_auto_ack_total.sum(['cluster', 'node']).rate('PT1M') + rabbitmq_global_messages_delivered_consume_manual_ack_total.sum(['cluster', 'node']).rate('PT1M') + rabbitmq_global_messages_delivered_get_auto_ack_total.sum(['cluster', 'node']).rate('PT1M') + rabbitmq_global_messages_delivered_get_auto_ack_total.sum(['cluster', 'node']).rate('PT1M') + rabbitmq_global_messages_delivered_get_manual_ack_total.sum(['cluster', 'node']).rate('PT1M')
  - name: consumer_total
    exp: rabbitmq_consumers.sum(['cluster', 'node'])
  - name: channel_total
    exp: rabbitmq_channels.sum(['cluster', 'node'])

  - name: allocated_used_percent
    exp: erlang_vm_allocators.tagEqual('usage' , 'blocks_size').sum(['cluster', 'node']) / erlang_vm_allocators.tagEqual('usage' , 'carriers_size').sum(['cluster', 'node']) * 10000
  - name: allocated_unused_percent
    exp: (erlang_vm_allocators.tagEqual('usage' , 'carriers_size').sum(['cluster', 'node']) - erlang_vm_allocators.tagEqual('usage' , 'blocks_size').sum(['cluster', 'node'])) / erlang_vm_allocators.tagEqual('usage' , 'carriers_size').sum(['cluster', 'node']) * 10000
  - name: allocated_used_bytes
    exp: erlang_vm_allocators.tagEqual('usage' , 'blocks_size').sum(['cluster', 'node'])
  - name: allocated_unused_bytes
    exp: erlang_vm_allocators.tagEqual('usage' , 'carriers_size').sum(['cluster', 'node']) - erlang_vm_allocators.tagEqual('usage' , 'blocks_size').sum(['cluster', 'node'])
  - name: allocated_total_bytes
    exp: erlang_vm_allocators.tagEqual('usage' , 'carriers_size').sum(['cluster', 'node'])
  - name: process_resident_memory_bytes
    exp: rabbitmq_process_resident_memory_bytes.sum(['cluster', 'node'])

  - name: allocated_by_type
    exp: erlang_vm_allocators.tagEqual('usage' , 'carriers_size').sum(['cluster', 'node', 'alloc'])
  - name: allocated_multiblock_used
    exp: erlang_vm_allocators.tagEqual('usage' , 'blocks_size' , 'kind', 'mbcs').sum(['cluster', 'node', 'alloc'])
  - name: allocated_multiblock_unused
    exp: erlang_vm_allocators.tagEqual('usage' , 'carriers_size' , 'kind', 'mbcs').sum(['cluster', 'node', 'alloc'])
  - name: allocated_multiblock_pool_used
    exp: erlang_vm_allocators.tagEqual('usage' , 'blocks_size' , 'kind', 'mbcs_pool').sum(['cluster', 'node', 'alloc'])
  - name: allocated_multiblock_pool_unused
    exp: erlang_vm_allocators.tagEqual('usage' , 'carriers_size' , 'kind', 'mbcs_pool').sum(['cluster', 'node', 'alloc'])
  - name: allocated_singleblock_used
    exp: erlang_vm_allocators.tagEqual('usage' , 'blocks_size' , 'kind', 'mbcs').sum(['cluster', 'node', 'alloc'])
  - name: allocated_singleblock_unused
    exp: erlang_vm_allocators.tagEqual('usage' , 'carriers_size' , 'kind', 'mbcs').sum(['cluster', 'node', 'alloc'])